package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.SoulTest;
import com.tanhua.dubbo.api.db.SoulTestApi;
import com.tanhua.dubbo.mapper.SoulTestMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


@DubboService
public class SoulTestApiImpl implements SoulTestApi {

    @Autowired
    private SoulTestMapper soulTestMapper;

    @Override
    public SoulTest findByUserId(String userId) {

        SoulTest soulTest = soulTestMapper.selectById(userId);
        return soulTest;
    }

    @Override
    public SoulTest findByUserIdAndQuestionnaireId(String userId, String questionnaireId) {
        QueryWrapper<SoulTest> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SoulTest::getUserId,userId);
        wrapper.lambda().eq(SoulTest::getQuestionnaireId,questionnaireId);
        SoulTest soulTest = soulTestMapper.selectOne(wrapper);
        return soulTest;
    }

    @Override
    public void save(SoulTest soulTest) {
        soulTestMapper.insert(soulTest);
    }

    @Override
    public void update(SoulTest soulTest) {
        soulTestMapper.updateById(soulTest);
    }

    @Override
    public List<SoulTest> findByReportId(String reportId) {
        QueryWrapper<SoulTest> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SoulTest::getReportId,reportId);
        List<SoulTest> soulTestList = soulTestMapper.selectList(wrapper);
        return soulTestList;


    }
}
